<template>
	<uni-popup ref="privacyPop">
		<view class="privacy-body">
			<view class="privacy-title">
				隐私协议说明
			</view>
			<view class="privacy-content">
				在您使用【运必达小程序】服务之前，请仔细阅读<text @click="openPrivacyContract" style="color: #2B7CFF;">{{ privacyContractName }}</text>,如您同意请点击同意开始使用。
				
			</view>
			<view class="privacy-foot">
				<button id="agree-btn"
				          type="default"
									class="reset-button cancel-btn"
									@tap="cancel"
				        >拒绝</button>
				<button id="agree-btn"
				          type="default"
				          open-type="agreePrivacyAuthorization"
				          class="reset-button primary-btn"
				          @agreeprivacyauthorization="handleAgree"
				        >同意</button>
			</view>
		</view>
	</uni-popup>
</template>

<script>
	export default {
		name:"privacyPopup",
		data() {
			return {
				privacyContractName: ''
			};
		},
		created() {
			console.log(wx.getPrivacySetting)
			if (wx.getPrivacySetting) {
				wx.getPrivacySetting({
					success: res => {
							console.log("是否需要授权：", res.needAuthorization, "隐私协议的名称为：", res.privacyContractName)
							
							if (res.needAuthorization) {
								this.privacyContractName = res.privacyContractName
								this.show()
							}
					},
					fail: () => { },
					complete: () => { },
				})
			}
			
		},
		methods: {
			show() {
				this.$nextTick(()=>{
					this.$refs.privacyPop.open()
				})
			},
			cancel() {
				this.$refs.privacyPop.close()
				this.$emit('disagree')
			},
			handleAgree() {
				this.$refs.privacyPop.close()
				this.$emit('agree')
			},
			openPrivacyContract() {
				wx.openPrivacyContract({
					success: res => {
						console.log('openPrivacyContract success')
					},
					fail: res => {
						console.error('openPrivacyContract fail', res)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.reset-button {
	  padding: 0;
	  margin: 0;
	  font-size: inherit;
	  background-color: transparent;
	  color: inherit;
	  position: relative;
	  border: 0rpx;
	  /* #ifndef APP-NVUE */
	  display: flex;
	  /* #endif */
	  align-items: center;
	  justify-content: center;
	  box-sizing: border-box;
	  text-align: center;
	  text-decoration: none;
	  white-space: nowrap;
	  vertical-align: baseline;
	  transform: translate(0, 0);
	}
	/* .reset-button.button-hover {
	  transform: translate(1px, 1px);
	  background: none;
	} */
	
	.reset-button::after {
	  border: none;
	}
.privacy-body {
	background-color: #fff;
	border-radius: 20rpx;
	padding: 30rpx;
	width: 540rpx;
	button {
		flex: 1;
		height: 80rpx;
	}
}
.privacy-title {
	text-align: center;
	font-size: 36rpx;
	font-weight: 600;
}
.privacy-content {
	padding: 50rpx 30rpx;
	font-size: 28rpx;
	color: #333;
	line-height: 45rpx;
}
.privacy-foot {
	display: flex;
}
.cancel-btn {
	background-color: #f5f5f5;
	margin-right: 30rpx;
}
.primary-btn {
	background-color: #2B7CFF !important;
	color: #fff !important;
}
</style>